home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / web / noweb / src / shell / cpif < prev    next >
Text File  |  1995-02-24  |  545b  |  32 lines

  1. #!/bin/sh
  2.  
  3. # cpif [ -eq -ne ] file...
  4. # copy standard input to each of the named files
  5. # if new * old is true or old doesn't exist;
  6. # * defaults to -ne
  7.  
  8. PATH=/bin:/usr/bin
  9.  
  10. # set -x
  11. op=-ne
  12. case "$1" in
  13. -eq|-ne)    op=$1; shift ;;
  14. -*)        echo 'Usage: '`basename $0`' [ -eq -ne ] file...' 1>&2; exit 2
  15. esac
  16. case $# in
  17. 0)        echo 'Usage: '`basename $0`' [ -eq -ne ] file...' 1>&2; exit 2
  18. esac
  19.  
  20. new=/tmp/$$
  21. trap 'rm -f $new; exit 1' 1 2 15    # clean up files
  22.  
  23. cat >$new
  24. for i
  25. do
  26.     cmp -s $new $i
  27.     case $op$? in
  28.     -eq0|-ne1|*2)    cp $new $i
  29.     esac
  30. done
  31. rm -f $new
  32.